package com.zw.web.validation.dto;

import lombok.Data;
import org.springframework.validation.annotation.Validated;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.groups.Default;

/**
 * @author zhangwei
 * @Valid 嵌套校验
 * @Validated 分组校验
 * groups
 */
@Data
@Validated
public class SysUserDto {
    @NotNull(groups = {UserUpdate.class})
    @Min(value = 1, message = "用户ID格式不正确", groups = {UserUpdate.class})
    private Long userId;
    /**
     * 1 过长字段
     * 必须是字母开头   数字+字母的组合 长度8-16
     */
    @NotNull
    @Pattern(regexp = "^[a-zA-Z][a-zA-Z0-9]{7,15}$", message = "用户名格式不正确")
    private String username;
    @NotNull
    @Pattern(regexp = "^[A-Z][a-zA-Z0-9]{7,17}$", message = "密码格式不正确")
    private String password;
    @NotNull
    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
    private String phone;

    @Valid
    @NotNull(message = "对象不能空", groups = {UserUpdate.class})
    private SysUserDetailDto sysUserDetailDto;

    public interface UserSave extends Default {
    }

    public interface UserUpdate extends Default {

    }


}
